package cn.ygh.bbo.system.web.controller;

import cn.ygh.bbo.framerwork.core.ClientInfo;
import cn.ygh.bbo.framerwork.core.Grid;
import cn.ygh.bbo.common.exception.TipException;
import cn.ygh.bbo.system.bean.LoginLog;
import cn.ygh.bbo.system.service.LoginLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 描述：登陆日志  RestPageController
 * @author ygh
 */
@Controller
@RequestMapping("/restpage/loginLog")
public class LoginLogController {

    private final Logger logger= LoggerFactory.getLogger(getClass());

    @Autowired
    LoginLogService loginLogService;

    /**
     * 查询列表api 带总数
     * @param request 请求
     * @param response 响应
     * @param clientInfo 查询条件
     * @return
     */
    @RequiresPermissions("system:loginLog:query")
    @ResponseBody
    @RequestMapping(value = "/query",method = RequestMethod.GET)
    public Grid grid(HttpServletRequest request, HttpServletResponse response, ClientInfo clientInfo, LoginLog search){
        search.setOrderValue(clientInfo.realSort().trim());
        if (clientInfo.getPageNo()==0){
            throw new TipException("pageNum can not zero");
        }
        Grid grid=loginLogService.listGrid(search,PageRequest.of(clientInfo.getPageNo(),clientInfo.getPageSize()));
        return grid;
    }

    /**
     * 详细
     * @param id
     * @return
     */
    @RequiresPermissions("system:loginLog:show")
    @ResponseBody
    @RequestMapping(value = "/get",method = RequestMethod.GET)
    public LoginLog get(HttpServletRequest request, HttpServletResponse response, Integer id){
        LoginLog result=loginLogService.getById(id);
        return result;
    }


}
